<?php

namespace App\Http\Controllers\Photo;

use App\Models\Photos\Album;
use App\Traits\UploadQiuniuTrait;
use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class AlbumController extends Controller
{
    use UploadQiuniuTrait;

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $albums = Album::orderBy('id', 'desc')->get();

        return view('photos.album', ['albums' => $albums]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {

    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function store(Request $request)
    {
        $data          = $request->all();

        if ($request->file('cover')) {
            $data['cover'] = env('QINIU_HOST').'/'.$this->upload($request->file('cover'));
        }

        $data = Album::create($data)->toArray();

        file_put_contents('/tmp/sss', var_export($data,1));

        return $this->index();
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int                      $id
     *
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
